<template>
	<view>
		<view>
			<view class="row">
				<view class="nominal">合同名称：</view><view class="text">{{details.proName}}</view>
			</view>
			<view class="row">
				<view class="nominal">装修用户：</view><view class="text">{{details.userName}}</view>
			</view>
			<view class="row" @click="toChat1">
				<view class="nominal">设计师：</view><view class="name">{{details.designerName}}</view>
			</view>
			<view class="row" @click="toChat2">
				<view class="nominal">施工团队：</view><view class="name">{{details.consName}}</view>
			</view>
			<view class="row">
				<view class="nominal">装修开始时间：</view><view class="text">{{details.starttime}}</view>
			</view>
			<view class="row">
				<view class="nominal">装修结束时间：</view><view class="text">{{details.endtime}}</view>
			</view>
		</view>

		
		<button @click="open">查看合同原件</button>
		<uni-popup ref="popup" type="bottom">
			<image :src="detailes.picPath" mode=""></image>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() { 
			return {
				details:'',
				proId:'',
				detailes:'',
			}
		},
		onLoad:function(option) {
			this.proId = option.proId,
			this.getPicture();
		},
		methods: {
			getPicture:function(){
				uni.request({
					url:"http://"+global.address+":8081/project/selectMyProject/"+this.proId,
					method:"GET",
					success:(res) => {
						this.details = res.data
					}
				})
			},
			toChat1:function(){
				uni.request({
					url:'http://'+global.address+':8081/designer/selectById/'+this.details.designerId,
					success: (res) => {
						uni.navigateTo({
							url:'../../message/chatpage?role='+JSON.stringify(res.data)
						})
					}
				})
			},
			toChat2:function(){
				console.log(JSON.stringify(this.details))
				uni.request({
					url:'http://'+global.address+':8081/construction/selectById/'+this.details.consId,
					success: (res) => {
						console.log(JSON.stringify(res.data))
						uni.navigateTo({
							url:'../../message/chatpage?role='+JSON.stringify(res.data)
						})
					}
				})
			},
			open(){
				// this.$refs.popup.show();
				uni.request({
					url:"http://"+global.address+":8081/picture/getContractPicByProId?proId="+this.proId,
					method:"GET",
					success: (res) => {
						// this.detailes = res.data
						if(res.data === '图片不存在'){
							uni.showToast({
								icon:'loading',
							    title: '还未上传图片',
							    duration: 500
							});
						}else{
							this.previewPhoto(res.data)
						}
					}
				})
			},
			previewPhoto(path) {
				let imgs = [];
				imgs.push(path)
				uni.previewImage({
					urls: imgs,
					longPressActions: {
						itemList: ['发送给朋友', '保存图片', '收藏'],
						success: function(data) {
							console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
						},
						fail: function(err) {
							console.log(err.errMsg);
						}
					}
				});
			}
		}
	}
</script>

<style>
	.row{
		width: 100%;
		height: 90upx;
		display: flex;
		align-items: center;
	}
	.nominal{
		flex-shrink: 0;
		font-size: 32upx;
		color: #7d7d7d;
		}
		.text{
		width: 70%;
		margin-left: 10upx;
		overflow: hidden;
		text-overflow:ellipsis;
		white-space: nowrap;
		font-size: 32upx;
		}
		.name{
		width: 70%;
		color: #007AFF;
		margin-left: 10upx;
		overflow: hidden;
		text-overflow:ellipsis;
		white-space: nowrap;
		font-size: 32upx;
		}
</style>
